package com.lyy.lottery.dao.mapper;

import com.lyy.lottery.dao.dataobject.Encrypt;
import com.lyy.lottery.dao.dataobject.UserDo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //查询邮箱绑定的人数
    @Select("select count(*) from user where email=#{email}")
    int countByMail(@Param("email") String email);

    @Select("select count(*) from user where phone_number=#{phoneNumber}")
    int countByPhone(@Param("phoneNumber") Encrypt phoneNumber);

    @Insert("insert into user(user_name,email,identity,password,phone_number) values (#{userName},#{email},#{identity},#{password},#{phoneNumber})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(UserDo userDo);

    @Select("select * from user where email=#{email}")
    UserDo selectByMail(@Param("email") String email);

    @Select("select * from user where phone_number=#{phoneNumber}")
    UserDo selectByPhoneNumber(Encrypt phoneNumber);

    @Select("<script>"+
            " select * from user"+
                " <if test=\"identity!=null\">"+
                    " where identity=#{identity}"+
                " </if>"+
            " order by id desc"+
            " </script>"
            )
    List<UserDo> selectUserListByIdentity(@Param("identity") String identity);


    @Select("<script>"+
                " select id from user"+
                " where id in"+
                    " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
                        " #{item}" +
                    " </foreach>" +
            " </script>" )
    List<Long> selectExistByIds(@Param("items") List<Long> userIds);

    @Select("<script>" +
            " select * from user" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<UserDo> batchSelectByIds(@Param("items") List<Long> ids);
}

















